package com.hanrui.android.fragment.message.myvote;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanrui.android.R;
import com.hanrui.android.activity.download.MyDownLoadActivity;
import com.hanrui.android.activity.message.audit.VoteDetailActivity;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.FilesBean;
import com.hanrui.android.model.MyVoteRecordBean;
import com.hanrui.android.model.ProposalVoteDetailBean;
import com.hanrui.android.net.contract.message.myvote.MyVoteRecordContract;
import com.hanrui.android.net.presenter.message.myvote.MyVoteRecordPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 董事会已表决查看
 *
 */

public class MyVoteRecordFragment extends BaseFragment<MyVoteRecordPresenter> implements MyVoteRecordContract.View {
    @BindView(R.id.ll_addview)
    LinearLayout lladdview;

    String mid;

    List<FilesBean> filesBeanList = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_myvotehandle;
    }

    @Override
    protected void initInjector() { mFragmentComponent.inject(this); }

    @Override
    protected void initView(View view) {

        mid = getArguments().getString("mid");

        mPresenter.recordView(getActivity(),mid);

    }



    public static MyVoteRecordFragment newInstance(String mid) {
        MyVoteRecordFragment fragment = new MyVoteRecordFragment();
        Bundle bundle = new Bundle();
        bundle.putString("mid", mid);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void recordView(MyVoteRecordBean data) {

        if (null != data && null != data.getResultsList() && data.getResultsList().size() > 0) {

            for (int i = 0; i < data.getResultsList().size(); i++) {

                addViewItem(data.getResultsList().get(i));
            }

        }

    }


    //添加ViewItem
    private void addViewItem(final ProposalVoteDetailBean.ResultBean bean) {

        View hotelEvaluateView = View.inflate(getActivity(), R.layout.item_myvoterecord, null);
        TextView miniTitle = hotelEvaluateView.findViewById(R.id.mini_title);
        TextView billName = hotelEvaluateView.findViewById(R.id.bill_name);
        TextView thingTitle = hotelEvaluateView.findViewById(R.id.thing_title);
        TextView time = hotelEvaluateView.findViewById(R.id.time);
        TextView agree = hotelEvaluateView.findViewById(R.id.agree);
        TextView oppose = hotelEvaluateView.findViewById(R.id.oppose);
        TextView waiver = hotelEvaluateView.findViewById(R.id.waiver);
        TextView passType = hotelEvaluateView.findViewById(R.id.pass_type);
        ImageView enclosure = hotelEvaluateView.findViewById(R.id.enclosure);
        LinearLayout enclosureLl = hotelEvaluateView.findViewById(R.id.enclosure_ll);
        TextView voteDetail = hotelEvaluateView.findViewById(R.id.vote_detail);
        TextView enclosureNum = hotelEvaluateView.findViewById(R.id.enclosure_num);

        miniTitle.setText("议案信息");
        billName.setText(bean.getPROPOSAL());
        thingTitle.setText(bean.getOFFICENAME());
        time.setText(bean.getNAME());
        agree.setText(bean.getTONGYI()+"");
        oppose.setText(bean.getQIQUAN()+"");
        waiver.setText(bean.getFANDUI()+"");
        passType.setText(bean.getResultName());

        if (null != bean.getFileList() && bean.getFileList().size() > 0) {

            enclosureLl.setVisibility(View.VISIBLE);
            enclosureNum.setText("["+bean.getFileList().size()+"]");
            enclosure.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    MyDownLoadActivity.start(getActivity(),bean.getFileList());

                }
            });
        }

        voteDetail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                VoteDetailActivity.start(getActivity(),bean.getPROPOSALID());

            }
        });


        lladdview.addView(hotelEvaluateView);
    }
}
